package Task1.Threading;

import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import Task1.model.DongCat;
import Task1.model.XeCat;

public class OutThread implements Runnable {
    private Logger log = LoggerFactory.getLogger(OutThread.class);
    private List<Thread> listThrXeDi;

    public OutThread(int soXe, DongCat dongcat, int time) {
        listThrXeDi = new ArrayList<Thread>();
        for (int i = 0; i < soXe; i++) {
            XeCat xeOut = new XeCat(false, 0);
            xeOut.set_dongcat(dongcat);
            xeOut.setTime(time);
            Thread thrOut = new Thread(xeOut);           
            log.info("{} created! ", thrOut);
            listThrXeDi.add(thrOut);
            log.info("added {} to list {}", thrOut, listThrXeDi);
        }
    }

    public void run() {
        for (Thread thrOut : listThrXeDi) {
            if (!thrOut.isAlive()) {
                thrOut.start();
                log.info("{} is started.",thrOut);
            }
        }

    }
}
